package com.core.zyyz.pcmc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.zyyz.pcmc.domain.PcmcDataColumn;
import com.core.zyyz.pcmc.service.PcmcDataColumnService;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 数据列Controller
 *
 * @author LiuFushun
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/dataColumn/dataColumn")
public class PcmcDataColumnController extends BaseController
{
    @Autowired
    private PcmcDataColumnService pcmcDataColumnService;

    /**
     * 查询数据列列表
     */
    @PreAuthorize("@ss.hasPermi('dataColumn:dataColumn:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcDataColumn pcmcDataColumn)
    {
        startPage();
        List<PcmcDataColumn> list = pcmcDataColumnService.selectPcmcDataColumnList(pcmcDataColumn);
        return getDataTable(list);
    }

    /**
     * 导出数据列列表
     */
    @PreAuthorize("@ss.hasPermi('dataColumn:dataColumn:export')")
    @Log(title = "数据列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcmcDataColumn pcmcDataColumn)
    {
        List<PcmcDataColumn> list = pcmcDataColumnService.selectPcmcDataColumnList(pcmcDataColumn);
        ExcelUtil<PcmcDataColumn> util = new ExcelUtil<PcmcDataColumn>(PcmcDataColumn.class);
        util.exportExcel(response, list, "数据列数据");
    }

    /**
     * 获取数据列详细信息
     */
    @PreAuthorize("@ss.hasPermi('dataColumn:dataColumn:query')")
    @GetMapping(value = "/{tableCode}")
    public AjaxResult getInfo(@PathVariable("tableCode") String tableCode)
    {
        return success(pcmcDataColumnService.selectPcmcDataColumnByTableCode(tableCode));
    }

    /**
     * 新增数据列
     */
    @PreAuthorize("@ss.hasPermi('dataColumn:dataColumn:add')")
    @Log(title = "数据列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmcDataColumn pcmcDataColumn)
    {
        return toAjax(pcmcDataColumnService.insertPcmcDataColumn(pcmcDataColumn));
    }

    /**
     * 修改数据列
     */
    @PreAuthorize("@ss.hasPermi('dataColumn:dataColumn:edit')")
    @Log(title = "数据列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmcDataColumn pcmcDataColumn)
    {
        return toAjax(pcmcDataColumnService.updatePcmcDataColumn(pcmcDataColumn));
    }

    /**
     * 删除数据列
     */
    @PreAuthorize("@ss.hasPermi('dataColumn:dataColumn:remove')")
    @Log(title = "数据列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tableCodes}")
    public AjaxResult remove(@PathVariable String[] tableCodes)
    {
        return toAjax(pcmcDataColumnService.deletePcmcDataColumnByTableCodes(tableCodes));
    }
}
